Page({
  data: {
    currentTab: 'red', // 默认显示红榜
    redList: [
      {
        id: 1,
        name: '老东江米粉',
        rank: 'W TOP 1',
        rating: 4.9,
        reviews: 1286,
        description: '汤头鲜美，米粉爽滑，卤肉入味，是桂林必吃的经典美食',
        address: '秀峰区解放西路28号',
        image: '/images/banner1.png'
      },
      {
        id: 2,
        name: '谢大姐啤酒鱼',
        rank: 'W TOP 2',
        rating: 4.8,
        reviews: 976,
        description: '鱼肉鲜嫩，啤酒香浓，微辣开胃，阳朔特色美食代表',
        address: '阳朔县西街口',
        image: '/images/banner1.png'
      },
      {
        id: 3,
        name: '椿记烧鹅',
        rank: 'Y TOP 3',
        rating: 4.7,
        reviews: 842,
        description: '田螺肉与猪肉完美结合，口感丰富，桂林特色创意菜',
        address: '七星区七星路30号',
        image: '/images/banner1.png'
      },
      {
        id: 4,
        name: '阿甘酒家',
        rank: '推荐',
        rating: 4.6,
        reviews: 723,
        description: '芋头绵软，扣肉肥而不腻，传统桂林宴席菜',
        address: '象山区中山中路22号',
        image: '/images/banner1.png'
      },
      {
        id: 5,
        name: '崇善米粉',
        rank: '推荐',
        rating: 4.5,
        reviews: 658,
        description: '马肉鲜香，米粉浓郁，桂林特色包点代表',
        address: '叠彩区中山北路45号',
        image: '/images/banner1.png'
      }
    ],
    blackList: [
      {
        id: 1,
        name: '某街边小吃摊',
        rank: '警告',
        reason: '卫生条件差，多人反馈腹泻情况',
        address: '某夜市入口附近',
        image: '/images/banner1.png'
      },
      {
        id: 2,
        name: '桂林XX快餐店',
        rank: '差评',
        reason: '食材不新鲜，服务态度恶劣',
        address: '市中心步行街旁',
        image: '/images/banner1.png'
      }
    ]
  },

  onLoad() {
    this.formatRatings();
    this.setData({ currentList: this.data.redList });
  },

  switchTab(e) {
    const tab = e.currentTarget.dataset.tab;
    const currentList = this.data[`${tab}List`];
    this.setData({ currentTab: tab, currentList });
  },

  formatRatings() {
    const redList = this.data.redList.map(item => ({
      ...item,
      ratingArray: Array(Math.floor(item.rating)).fill(1)
    }));

    this.setData({ redList });
  }
});